package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.EvVehicle;
import com.ruoyi.system.service.IEvVehicleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 电动车信息Controller
 * 
 * @author wtd1
 * @date 2025-11-15
 */
@RestController
@RequestMapping("/system/vehicleofwtd")
public class EvVehicleController extends BaseController
{
    @Autowired
    private IEvVehicleService evVehicleService;

    /**
     * 查询电动车信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:vehicleofwtd:list')")
    @GetMapping("/list")
    public TableDataInfo list(EvVehicle evVehicle)
    {
        startPage();
        List<EvVehicle> list = evVehicleService.selectEvVehicleList(evVehicle);
        return getDataTable(list);
    }

    /**
     * 导出电动车信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:vehicleofwtd:export')")
    @Log(title = "电动车信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EvVehicle evVehicle)
    {
        List<EvVehicle> list = evVehicleService.selectEvVehicleList(evVehicle);
        ExcelUtil<EvVehicle> util = new ExcelUtil<EvVehicle>(EvVehicle.class);
        util.exportExcel(response, list, "电动车信息数据");
    }

    /**
     * 获取电动车信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:vehicleofwtd:query')")
    @GetMapping(value = "/{vehicleId}")
    public AjaxResult getInfo(@PathVariable("vehicleId") Long vehicleId)
    {
        return success(evVehicleService.selectEvVehicleByVehicleId(vehicleId));
    }

    /**
     * 新增电动车信息
     */
    @PreAuthorize("@ss.hasPermi('system:vehicleofwtd:add')")
    @Log(title = "电动车信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EvVehicle evVehicle)
    {
        try
        {
            return toAjax(evVehicleService.insertEvVehicle(evVehicle));
        }
        catch (DuplicateKeyException e)
        {
            return AjaxResult.error("车牌号已存在，请更换车牌号");
        }
    }

    /**
     * 修改电动车信息
     */
    @PreAuthorize("@ss.hasPermi('system:vehicleofwtd:edit')")
    @Log(title = "电动车信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EvVehicle evVehicle)
    {
        try
        {
            return toAjax(evVehicleService.updateEvVehicle(evVehicle));
        }
        catch (DuplicateKeyException e)
        {
            return AjaxResult.error("车牌号已存在，请更换车牌号");
        }
    }

    /**
     * 删除电动车信息
     */
    @PreAuthorize("@ss.hasPermi('system:vehicleofwtd:remove')")
    @Log(title = "电动车信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{vehicleIds}")
    public AjaxResult remove(@PathVariable Long[] vehicleIds)
    {
        return toAjax(evVehicleService.deleteEvVehicleByVehicleIds(vehicleIds));
    }
}
